home *** CD-ROM | disk | FTP | other *** search
/ Crack It! / Crack It!.iso / CONTENT / DISKEDIT / TSSR.ASM < prev   
Assembly Source File  |  1996-09-09  |  8KB  |  175 lines

  1. ;***
  2. ;
  3. ;TSSR.ASM
  4. ;Screen Save and Restore Routines for Turbo Pascal
  5. ;(C)Copyright Gerard Paul Java 1996
  6. ;
  7. ;Interface Source File
  8. ;
  9. ;
  10. ;These routines save and restore the 25x80 screen.  These are useful for
  11. ;pop-up and pop-down windows.  This module is not to be run stand-alone.
  12. ;Used for portability and speed with high-level language programs.
  13. ;
  14. ;If these routines are used with 25x40 text screens, two screen pages will
  15. ;be saved or restored.
  16. ;
  17. ;Always call SetTSSRValues before any of the other two routines.  Use
  18. ;SaveScreen before RestoreScreen.
  19. ;
  20. ;Assemble with the Borland Turbo Assembler Version 1.0 or later.
  21. ;
  22. ;This module is designed to be linked into Turbo Pascal units, and these
  23. ;routines are intended to be declared in the interface sections.  The
  24. ;routines therefore make use of the FAR call model.
  25. ;
  26. ;Declare these procedures in Pascal as:
  27. ;
  28. ;    procedure SetTSSRValues;                                 external;
  29. ;    procedure SaveScreen(var BuffAddr: ScreenBufferType);    external;
  30. ;    procedure RestoreScreen(var BuffAddr: ScreenBufferType); external;
  31. ;
  32. ;where ScreenBufferType is declared as:
  33. ;
  34. ;    type
  35. ;      ScreenBufferType = array[1..2000] of word;
  36. ;
  37. ;These procedures make use of the Turbo Pascal Crt unit's CheckSnow variable
  38. ;to determine whether to execute the snow-elimination code on CGA machines.
  39. ;
  40. ;This module requires the Crt unit included in the unit's compilation.
  41. ;
  42. ;***
  43. ;
  44.  
  45.  
  46. SAVE_SIZE               EQU     4000           ;Screen size is 4000 bytes.
  47. STORE_COUNT             EQU     2000           ;Count 2000 times.
  48. CGA_STAT_REG            EQU     3DAH
  49.  
  50. FALSE                   EQU     0
  51. TRUE                    EQU     1
  52. boolean                 EQU     BYTE
  53. pointer                 EQU     DWORD
  54.  
  55. .MODEL TPASCAL                                    ;TASM Turbo Pascal support.
  56.  
  57. .DATA
  58.  
  59. SCREEN_SEG              DW      ?                    ;Screen segment
  60. MONO                    DB      ?                    ;TRUE if mono.
  61.  
  62.                         EXTRN   CheckSnow: boolean   ;Crt CheckSnow variable.
  63.  
  64. .CODE
  65.  
  66.  
  67. ;-----Make routines available to the linker-----
  68.  
  69.                 PUBLIC  SaveScreen
  70.                 PUBLIC  RestoreScreen
  71.                 PUBLIC  SetTSSRValues
  72.  
  73. ;
  74. ;-------------------------Procedure SaveScreen-------------------------------
  75. ;Source segment is DS, pointing to B800h or B000h depending on SetTSSRValues.
  76. ;Target segment is pointed to by ES, storage buffer pointed to by DI.
  77. ;---------------------------------------------------------------------------
  78. ;
  79. ;procedure SaveScreen(var Buffer: ScreenBufferType);
  80. ;
  81. SaveScreen      PROC    FAR     BuffAddr: pointer
  82.                 PUSH    DS                       ;Save DS.
  83.                 CLD                              ;Clear direction flag.
  84.                 MOV     AL,MONO
  85.                 MOV     AH,CheckSnow
  86.                 MOV     DS,SCREEN_SEG            ;DS points to screen.
  87.                 MOV     CX,STORE_COUNT           ;CX=no of chars in screen.
  88.                 MOV     DX,CGA_STAT_REG          ;Load status register.
  89.                 XOR     SI,SI                    ;Point to screen.
  90.                 LES     DI,BuffAddr              ;Load buffer address in DI.
  91.                 CMP     AL,TRUE                  ;Mono? 
  92.                 JE      READ_NO_SNOW             ;Yes, read with no snow.
  93.                 CMP     AH,TRUE                  ;Snow-checking on?
  94.                 JNE     READ_NO_SNOW             ;No, read with no snow.
  95. R_LWAIT:        IN      AL,DX                    ;Get status.
  96.                 RCR     AL,1                     ;Low?
  97.                 JC      R_LWAIT                  ;No, loop until so.
  98.                 CLI                              ;Shut off interrupts.
  99. R_HWAIT:        IN      AL,DX                    ;Get status again.
  100.                 RCR     AL,1                     ;High?
  101.                 JNC     R_HWAIT                  ;No, loop until so.
  102.                 MOVSW                            ;Move character.
  103.                 STI                              ;Interrupts back on.
  104.                 LOOP    R_LWAIT                  ;Loop back.
  105.                 JMP     R_DONE                   ;Done.
  106. READ_NO_SNOW:   REP     MOVSW                    ;Move with no snow.
  107. R_DONE:         POP     DS                       ;Restore DS.
  108.                 RET                              ;Return to caller.
  109. SaveScreen      ENDP
  110.  
  111.  
  112. ;
  113. ;-------------------------Procedure RestoreScreen---------------------------
  114. ;Source segment is pointed to by DS, storage buffer pointed to by SI.
  115. ;Target segment is pointed to by ES, either B800h or B000h, depending on
  116. ;Screen_Seg, returned by SetTSSRValues.
  117. ;---------------------------------------------------------------------------
  118. ;
  119. ;procedure RestoreScreen(var BuffAddr: ScreenBufferType);
  120. ;
  121. RestoreScreen   PROC    FAR     BuffAddr: pointer
  122.                 CLD                              ;Clear direction flag.
  123.                 MOV     AL,MONO
  124.                 MOV     AH,CheckSnow
  125. INIT_LOAD:      MOV     ES,SCREEN_SEG            ;Put screen segment in ES.
  126.                 MOV     CX,STORE_COUNT           ;Size to restore.
  127.                 MOV     DX,CGA_STAT_REG          ;Load CGA status register.
  128.                 XOR     DI,DI                    ;Point to init screen postn.
  129.                 LDS     SI,BuffAddr              ;Load buffer address.
  130.                 CMP     AL,TRUE                  ;Mono?
  131.                 JE      WRITE_NO_SNOW            ;Yes, no snow.
  132.                 CMP     AH,TRUE                  ;Snow-checking on?
  133.                 JNE     WRITE_NO_SNOW            ;No, no snow, store bytes.
  134. W_LWAIT:        IN      AL,DX                    ;Get status.
  135.                 RCR     AL,1                     ;Low?
  136.                 JC      W_LWAIT                  ;No, loop until so.
  137.                 CLI                              ;Shut off interrupts.
  138. W_HWAIT:        IN      AL,DX                    ;Get status again.
  139.                 RCR     AL,1                     ;High?
  140.                 JNC     W_HWAIT                  ;No, loop until so.
  141. MOV_TO_SCREEN:  MOVSW                            ;Move character to screen.
  142.                 STI                              ;Interrupts back on.
  143.                 LOOP    W_LWAIT                  ;Do it CX times.
  144.                 JMP     W_DONE                   ;Done.
  145. WRITE_NO_SNOW:  REP     MOVSW                    ;Move with no snow.
  146. W_DONE:         RET                              ;Return to caller.
  147. RestoreScreen   ENDP
  148.  
  149. ;
  150. ;----------------------------------------------------------------------------
  151. ;SetTSSRValues: Determines the proper screen segment to operate on and sets a
  152. ;flag if the system is equipped with a CGA, for use in case it "snows".  This
  153. ;routine must be called before SaveScreen, which must be called before
  154. ;RestoreScreen.  Calling any routine without the required calls produces
  155. ;unpredictable results.
  156. ;----------------------------------------------------------------------------
  157. ;
  158. ;procedure SetTSSRValues;
  159. ;
  160. SetTSSRValues   PROC    FAR
  161.                 MOV     AH,15                    ;Retreive video mode.
  162.                 INT     10H
  163.                 CMP     AL,7                     ;Mono?
  164.                 JE      MONO_SETUP               ;Yes, get segment.
  165. COLOR_SETUP:    MOV     SCREEN_SEG,0B800H
  166.                 MOV     MONO,FALSE
  167.                 JMP     DONE
  168. MONO_SETUP:     MOV     SCREEN_SEG,0B000H
  169.                 MOV     MONO,TRUE
  170. DONE:           RET                              ;Return to caller.
  171. SetTSSRValues   ENDP
  172.  
  173.                 END
  174.  
  175.